package hackthon.dao;

import hackthon.core.Constant;
import hackthon.pojo.Register;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by wuwenhao on 15/1/8.
 */

@Repository
public class RegisterDao extends BaseDao{

    public int updateRegisterStatus(int emailId, String attendEmail, int status){
        Register register = new Register();
        register.setAttendEmail(attendEmail);
        register.setStatus(status);
        register.setEmailId(emailId);
        getSqlMapClientTemplate().update(getNameSpace()+".SuccessStatus", register);
        return 1;
    }

    public List getCurrentEmail(String attendEmail){
        Register register = new Register();
        register.setAttendEmail(attendEmail);
        register.setStatus(Constant.OVER);
        return getSqlMapClientTemplate().queryForList(getNameSpace()+".getCurrentEmailList",register);

    }

    public List getListByEmailId(int emailId){
        return getSqlMapClientTemplate().queryForList(getNameSpace()+".getByEmailId",emailId);
    }
    @Override
    public String getNameSpace() {
        return "register";
    }

    public int initRegister(int emailId, String attendAddress){

        Register register = new Register();
        register.setEmailId(emailId);
        register.setStatus(Constant.REJECTED);
        register.setAttendEmail(attendAddress);
        return (Integer)getSqlMapClientTemplate().insert(getNameSpace()+".initRegister", register);

    }

    public Register getByEmailAndAttend(int emailId, String attendEmail){
        Register register = new Register();
        register.setAttendEmail(attendEmail);
        register.setEmailId(emailId);
        return (Register)getSqlMapClientTemplate().queryForObject(getNameSpace()+".getByEmailAndAttend",register);
    }
}
